<template>
  <div>
    <el-form :inline="true" :model="search" class="demo-form-inline">
     
      <el-row class="table-head-box">
         <el-col :span="4" class="flex flex-start">
           <el-button type="primary" icon="el-icon-plus" plain @click="addStoreHandler()">添加商户</el-button>
        </el-col>
        <el-col :span="20" class="flex flex-end input-box">
          <el-form-item label="门店电话：">
            <el-input v-model="search.eqParam.mobile" clearable placeholder="门店电话"></el-input>
          </el-form-item>
         
          <el-form-item label="门店名称">
            <el-input v-model="search.lkParam.storeName" clearable placeholder="门店名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="searchUserHandler">查询</el-button>
            
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>
    <el-table :data="userList" border style="width: 100%" tooltip-effect="dark" size="mini">
      <el-table-column type="selection" width="55">
      </el-table-column>
       <el-table-column  prop="storeId" label="商户编号" width="150">
      </el-table-column>
      <el-table-column  prop="mobile" label="电话" width="150">
      </el-table-column>
      <el-table-column  prop="storeName" label="门店名称" width="150">
      </el-table-column>
      <el-table-column prop="storeAddr" label="门店地址" width="120">
      </el-table-column>
      <el-table-column prop="storeStar" label="门店星级" width="120">
        
          <template slot-scope="scope">
            <i class="el-icon-star-on" style="color:orange" v-for="item in scope.row.storeStar"></i>
         </template>
      </el-table-column>
       <el-table-column prop="storeLead" label="门店负责人" width="120">
      </el-table-column>
       <el-table-column prop="storeTtel" label="门店电话" width="120">
      </el-table-column>
       <el-table-column prop="type" label="门店类型" width="120">
         <template slot-scope="scope">
            <div v-if="scope.row.type==1">商品</div>
            <div v-if="scope.row.type==2">服务</div>
         </template>
      </el-table-column>
      <el-table-column prop="openingHours" label="营业时间" width="120">
      </el-table-column>
      <el-table-column prop="certificate" label="营业执照" width="120">
      </el-table-column>
      <el-table-column prop="storePhoto" label="门头照片" width="120">
         <template slot-scope="scope">
            <span><img :src="scope.row.storePhoto" width="50px" height="50px"></span>
          </template>
      </el-table-column>
      <el-table-column prop="indoorPhoto" label="室内照片" width="120">
          <template slot-scope="scope" v-if="scope.row.indoorPhoto"  >
            <span  v-for="item in scope.row.indoorPhoto.split(',')" v-bind:key="item.index">
              <img :src="item+'?imageView2/1/w/80/h/80'" width="50px" height="50px">
              </span>
          </template>
      </el-table-column>
      <el-table-column prop="openingHours" label="营业时间" width="120">
      </el-table-column>    

      <el-table-column prop="type" label="状态" width="300">
        <template slot-scope="scope">
          <div v-if="scope.row.status == 1">正常</div>
          <div v-if="scope.row.status == 2">休息</div>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="260">
        <template slot-scope="scope">
          <el-button v-if="scope.row.userName !='sys'" class="el-icon-edit" type="primary" size="mini" @click="updateUserHandler(scope.$index, scope.row)">编辑</el-button>
          <!-- <el-button v-if="scope.row.userName !='sys'" class="el-icon-delete" type="danger" size="mini" @click="deleteUserHandler(scope.$index, scope.row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- <el-row>
        <el-col :span="24" style="text-align:right;">
            <el-pagination background layout="total,prev, pager, next" :page-count="page.size" :total="page.total" @current-change="sizeChangeHandler"> </el-pagination>
        </el-col>
    </el-row> -->
    <MerchantAdd :merchantDialog="showMerchantDialog" :popMerchant="merchart"  v-on:close="closeHandler"></MerchantAdd>
  </div>

</template>
<script>
import {storePageListUrl} from '@/utils/common'
import MerchantAdd from './merchant-add.vue'
export default {
  components: {
    MerchantAdd
  },
  data() {
    return {
      userList: [],
      merchart: {},
      showMerchantDialog: false,
      authorizationDialog: false,
      userId: null,
      search: {
        current:1,
        size:10,
        total: 0,
        lkParam: {userName:""},
        eqParam:{},
      }
    };
  },
  mounted() {
    this.loadUsers();
  },
  methods: {
    addStoreHandler: function () {
      this.merchart = { type:1,status:1};
      this.showMerchantDialog = true;
    },
    updateUserHandler: function (index, row) {
      this.merchart = row;
      this.showMerchantDialog = true;
    },
    closeHandler: function () {
      this.showMerchantDialog = false;
      this.merchart={};
      this.loadUsers();
    },
    /**
     * 删除用户
     */
    deleteUserHandler: function (index, row) {
      this.$confirm("此操作将永久删除该用户, 是否继续?", "提示", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" })
        .then(() => {
          this.axios
            .post("/fc/su/del/" + row.userId)
            .then(response => {
                console.log(response)
              this.$message({ type: "success", message: "删除成功!"  });
              this.loadUsers();
            })
            .catch(response => {
                console.log(response)
              this.$message({ type: "warn", message: "删除失败!"  });
            });
        })
        .catch(() => {
          this.$message({ type: "info", message: "已取消删除" });
        });
    },
    loadUsers() {
      this.axios
        .post(storePageListUrl, this.search)
        .then(response => {
          var data = response.data.data;
          this.userList = data.records;
          this.search.total = data.total
        })
        .catch(response => {
          console.log("response -   " + response);
        });
    },
    sizeChangeHandler: function (value) {
      this.search.current = value;
      this.loadUsers();
    },
    searchUserHandler: function () {
      this.search.current=1
      this.loadUsers();
    }
  }
};
</script>
<style scoped>
.grid-content {
  text-align: left;
  height: 45px;
}
</style>
